package com.lehecai.core.api.business;

import com.lehecai.core.EnabledStatus;
import com.lehecai.core.api.AbstractApiResultBean;
import com.lehecai.core.lottery.BankType;
import com.lehecai.core.lottery.PlatformType;
import com.lehecai.core.lottery.RechargeType;
import com.lehecai.core.util.CoreDateUtils;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

/**
 * Created by zhangzq on 14-8-27.
 */
public class BankInfo extends AbstractApiResultBean {

    public static final String QUERY_ID = "id";
    public static final String QUERY_RECHARGE_PLATFORM = "recharge_platform";
    public static final String QUERY_PLATFORM= "platform";
    public static final String QUERY_PAY_TYPE = "pay_type";
    public static final String QUERY_BANK_NAME = "bank_name";
    public static final String QUERY_STATUS = "status";

    public static final String SET_RECHARGE_PLATFORM = "recharge_platform";
    public static final String SET_PLATFORM = "platform";
    public static final String SET_BANK_ID = "bank_id";
    public static final String SET_AREA = "area";
    public static final String SET_PAY_TYPE = "pay_type";
    public static final String SET_PIC_NAME = "pic_name";
    public static final String SET_STATUS = "status";

    private Integer id;
    private RechargeType rechargePlatform;                     //支付平台
    private PlatformType platform;                         //站点平台
    private BankType bankId;                           //银行
    private String bankName;                           //银行名称
    private AreaType area;                               //地区
    private PaymentType paymentType;                   //充值类别
    private String picName;                            //图片路径名称
    private EnabledStatus status;
    private Date timeLine;



    public static BankInfo convertFromJSONObject(JSONObject object) {
        if (object == null) {
            return null;
        }
        BankInfo bankInfo = new BankInfo();
        bankInfo.id = getInt(object, "id");
        bankInfo.rechargePlatform = RechargeType.getItem(object.getInt("recharge_platform"));
        bankInfo.platform = PlatformType.getItem(object.getInt("platform"));
        bankInfo.bankId = BankType.getItem(object.getInt("bank_id"));
        bankInfo.bankName = getString(object, "bank_name") ;
        bankInfo.area = AreaType.getItem(object.getInt("area"));
        bankInfo.paymentType = PaymentType.getItem(object.getInt("pay_type"));
        bankInfo.picName = getString(object, "pic_name") ;
        bankInfo.timeLine = CoreDateUtils.parseDate(("".equals(getString(object, "timeline")) || "0000-00-00 00:00:00".equals(getString(object, "timeline"))) ? null : getString(object, "timeline"), CoreDateUtils.DATETIME);
        bankInfo.status = EnabledStatus.getItem(object.getInt("status"));
        return bankInfo;
    }

    public static List<BankInfo> convertFromJSONArray(JSONArray array) {
        if (array == null) {
            return null;
        }
        List<BankInfo> list = new ArrayList<BankInfo>();
        for (Iterator<?> iterator = array.iterator(); iterator.hasNext();) {
            JSONObject object = (JSONObject) iterator.next();
            list.add(convertFromJSONObject(object));
        }
        return list;
    }


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public RechargeType getRechargePlatform() {
        return rechargePlatform;
    }

    public void setRechargePlatform(RechargeType rechargePlatform) {
        this.rechargePlatform = rechargePlatform;
    }

    public PlatformType getPlatform() {
        return platform;
    }

    public void setPlatform(PlatformType platform) {
        this.platform = platform;
    }

    public BankType getBankId() {
        return bankId;
    }

    public void setBankId(BankType bankId) {
        this.bankId = bankId;
    }

    public String getBankName() {
        return bankName;
    }

    public void setBankName(String bankName) {
        this.bankName = bankName;
    }

    public AreaType getArea() {
        return area;
    }

    public void setArea(AreaType area) {
        this.area = area;
    }

    public PaymentType getPaymentType() {
        return paymentType;
    }

    public void setPaymentType(PaymentType paymentType) {
        this.paymentType = paymentType;
    }

    public String getPicName() {
        return picName;
    }

    public void setPicName(String picName) {
        this.picName = picName;
    }

    public EnabledStatus getStatus() {
        return status;
    }

    public void setStatus(EnabledStatus status) {
        this.status = status;
    }

    public Date getTimeLine() {
        return timeLine;
    }

    public void setTimeLine(Date timeLine) {
        this.timeLine = timeLine;
    }
}
